using System;
using System.Collections.Generic;

[Serializable]
public class SkillAchievement : GameplayAchievement
{
	[Serializable]
	public class Stage
	{
		public int stageValue;

		public string reward;
	}

	public const AchievementResource.AchievementType achievementType = AchievementResource.AchievementType.SkillAchievement;

	public PlayerStatsManager.SkillType skillType;

	public List<Stage> stages = new List<Stage>();

	public override int achievedStagesCount
	{
		get
		{
			PlayerStats playerStats = GGPlayerSettings.instance.statsManager.playerStats;
			float skillValue = playerStats.GetSkillValue((int)skillType);
			for (int i = 0; i < stages.Count; i++)
			{
				if (skillValue < (float)stages[i].stageValue)
				{
					return i;
				}
			}
			return stages.Count;
		}
	}

	public override int totalStages
	{
		get
		{
			return stages.Count;
		}
	}

	public override bool shouldShowAchievementStageCompleted
	{
		get
		{
			return achievedStagesCount > model.stageReported;
		}
	}

	public override void OnShowAchievementStageCompleted(int achievedStageCount)
	{
		model.stageReported = achievedStageCount;
		ApplyRewards();
		Save();
	}

	public override void ApplyRewards()
	{
	}

	public override bool HasCompletedStage(int stageIndex)
	{
		if (stageIndex >= stages.Count)
		{
			return false;
		}
		return stageIndex < achievedStagesCount;
	}

	public override string GetStageText(int stageIndex)
	{
		if (stageIndex >= stages.Count)
		{
			return string.Empty;
		}
		return stages[stageIndex].stageValue.ToString();
	}

	public override void UpdateAchievement(GGStoryAchivementsController.UpdateAchievementParams updateParams)
	{
		if (shouldShowAchievementStageCompleted)
		{
			achivementController.AchievementAccomplishedNotify(this);
		}
	}
}
